package team.seekers.hula.user.school.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import team.seekers.hula.common.annotation.ApiResponseBody;
import team.seekers.hula.common.entity.PageResult;
import team.seekers.hula.user.school.entity.dto.SchoolAddDTO;
import team.seekers.hula.user.school.entity.dto.SchoolQueryDTO;
import team.seekers.hula.user.school.entity.dto.SchoolUpdateDTO;
import team.seekers.hula.user.school.entity.vo.SchoolInfoVO;
import team.seekers.hula.user.school.entity.vo.SchoolListVO;
import team.seekers.hula.user.school.service.SchoolService;

import javax.validation.Valid;

/**
 * 一个学校 前端控制器
 * @author hbc
 */
@Controller
@ApiResponseBody
@RequestMapping("/manage/school")
public class SchoolManageController {

    @Autowired
    private SchoolService schoolService;

    @ApiOperation(value = "根据学校id获取学校详细信息")
    @GetMapping("/get")
    public SchoolInfoVO getById(@RequestParam String id) {
        return schoolService.get(id);
    }

    @ApiOperation(value = "新建学校")
    @PostMapping("/add")
    public void add(@Valid @RequestBody SchoolAddDTO schoolAddDTO) {
        schoolService.add(schoolAddDTO);
    }

    @ApiOperation(value = "编辑学校")
    @PostMapping("/update")
    public void update(@Valid @RequestBody SchoolUpdateDTO schoolUpdateDTO) {
        schoolService.update(schoolUpdateDTO);
    }

    @ApiOperation(value = "解散学校")
    @DeleteMapping("/delete")
    public void delete(@RequestParam("id") String id) {
        schoolService.delete(id);
    }

    @ApiOperation(value = "根据学校名分页查询")
    @GetMapping("/page-query")
    public PageResult<SchoolListVO> pageQueryByTitle(SchoolQueryDTO schoolQueryDTO) {
        return schoolService.pageQuery(schoolQueryDTO);
    }



}

